/* eslint valid-jsdoc: "off" */

'use strict';
// const path = require('path');

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1608344837';
  // 添加 view 配置
  // config.view = {
  //   defaultViewEngine: 'nunjucks',
  //   mapping: {
  //     '.tpl': 'nunjucks',
  //   },
  // };
  // config.cluster = {
  //   https: {
  //     key: path.join(__dirname, '../httpskry/server.key'),
  //     cert: path.join(__dirname, '../httpskry/server.crt'),
  //   },
  // };
  // config.cluster = {
  //   https: {
  //     key: path.join(appInfo.baseDir, 'httpskey/server.key'),
  //     cert: path.join(appInfo.baseDir, 'httpskey/server.crt'),
  //   },
  // };
  exports.logger = {
    dir: 'a/logs',
    outputJSON: true,
    level: 'DEBUG',
  };

  // add your middleware config here
  // 方法一：在应用中使用中间件

  config.jwt = {
    secret: '123456',
    ignore: [ '/login' ],
  };

  config.mysql = {
    client: {
      // host
      host: '127.0.0.1',
      // 端口号
      port: '3306',
      // 用户名
      user: 'root',
      // 密码
      password: '123456',
      // 数据库名
      database: 'im',
    },
    // 是否加载到 app 上，默认开启
    app: true,
    // 是否加载到 agent 上，默认关闭
    agent: false,
  };


  config.redis = {
    client: {
      port: 6379,
      host: '127.0.0.1',
      password: null,
      db: 0,
    },

  };
  // 允许跨域方法
  config.cors = {
    origin: '*',
    allowMethods: 'GET, PUT,  POST, DELETE, PATCH',
  };


  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  exports.io = {
    init: { }, // passed to engine.io
    namespace: {
      '/': {
        connectionMiddleware: [ 'auth' ],
        packetMiddleware: [ 'filter' ],
      },
    },
    redis: {
      host: '127.0.0.1',
      port: 6379,
    },
  };


  return {
    ...config,
    ...userConfig,
  };
};
